'use strict';

const Service = require('egg').Service;
const SysMacAddrModel = require('../../model/SysMacAddrModel');
const sysMacAddrModel = new SysMacAddrModel();

/**
 * 创建者: rliang
 * 创建时间: 2019年08月26日 10:45:15
 * 功能描述: 菜单操作
 */
class sysMacAddrService extends Service {
    /**
     * 列表
     */
    async findMacAddrList(options) {
        const result = await sysMacAddrModel.findMacAddrList(this.app, options);
        return result;
    }

    /**
     * 添加macAddr
     */
    async addMacAddr(models) {
        const result = await sysMacAddrModel.addMacAddr(this.app, models);
        return result;
    }

    /**
     * 修改macAddr
     */
    async updateMacAddr(id, models) {
        const result = await sysMacAddrModel.updateMacAddr(this.app, id, models);
        return result;
    }

    /**
     * 删除macAddr
     */
    async delMacAddr(id) {
        const result = await sysMacAddrModel.delMacAddr(this.app, id);
        return result;
    }

    async findMacAddrCode(macAddr) {
        const result = await sysMacAddrModel.findMacAddrCode(this.app, macAddr);
        return result;
    }

    //获取所有的正常的macAddr
    async findNormalMacAddr() {
        const result = await sysMacAddrModel.findNormalMacAddr(this.app, macAddr);
        return result;
    }

    async findUserById(userId) {
        const result = await sysMacAddrModel.findUserById(this.app, userId);
        return result;
    }

    async findAllMacAddr() {
        const result = await sysMacAddrModel.findAllMacAddr(this.app);
        let res = [];
        if (result.length > 0) {
            res = result.map(obj => obj.mac_addr);
        }
        return res;
    }

}

module.exports = sysMacAddrService;